﻿miniSched.jsonApiClient = function () { };

miniSched.jsonApiClient.prototype.headers = {
    __RequestVerificationToken: $("input[name='__RequestVerificationToken']").val()
};

miniSched.jsonApiClient.prototype.request = function (type, settings) {
    var self = this;
    return $.ajax({
        url: settings.url,
        type: type,
        data: settings.data,
        headers: self.headers,
        dataType: "json",
        contentType:"application/json; charset=utf-8",
        success: function (data, textStatus, jqXHR) {
            var success = settings.success;
            if (success) {
                success(data);
            }
        },
        error: function (jqXHR, textStatus, errorThrown) {
            var error = settings.error;
            if (error) {
                error();
            }
            console.log(textStatus + " " + errorThrown);
        }
    });
};

miniSched.jsonApiClient.prototype.get = function (settings) {
    var self = this;
    return self.request("GET", settings);
};

miniSched.jsonApiClient.prototype.post = function (settings) {
    var self = this;
    return self.request("POST", settings);
};

miniSched.jsonApiClient.prototype.put = function (settings) {
    var self = this;
    return self.request("PUT", settings);
};

miniSched.jsonApiClient.prototype.delete = function (settings) {
    var self = this;
    return self.request("DELETE", settings);
};
